#!/usr/bin/env python3
import os, sys, django, socket
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "dmessage.settings")
django.setup()
from chat.views import *

def mkdir(dir_name) :
	try :
		os.mkdir(dir_name)
	except FileExistsError :
		print('exist:\t%s' % dir_name)
	if socket.gethostname() != 'laptop' :
		os.system('chown www-data:www-data -R %s' % dir_name)

if __name__ == "__main__":
	if input("1.	Create directories? [y/N]") == 'y' :
		mkdir('%s' % settings.MEDIA_ROOT)
		mkdir('%simages/' % settings.MEDIA_ROOT)
		mkdir('%simages/qrcode/' % settings.MEDIA_ROOT)
	if input('2.	Initialize qrcode files? [y/N]') == 'y' :
		for i in SessionInfo.objects.all() :
			ChatAction.qrcode_create(i.name, i.token)

